package com.pmh.hrs.util;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class HMacUtils {

	public static String sha1(String password) {
	    try {
	        MessageDigest md = MessageDigest.getInstance("SHA-256");
	        byte[] hash = md.digest(password.getBytes());
	        BigInteger bi = new BigInteger(1, hash);
	        return String.format("%0" + (hash.length << 1) + "x", bi);
	        
	    } catch (NoSuchAlgorithmException e) {
	        e.printStackTrace();
	    }
	    return null;
	}
	
	public static String encodePassword(String salt,String password) {
		return sha1(salt + sha1(password));
		
		
	}
	
	public static boolean isMatched(String hasshed_password,String salt,String input_password) {
		String encodePassword = encodePassword(salt,input_password);
		if(hasshed_password.equals(encodePassword)){
			return true;
		}
		return false;
	}
	
	public static void main(String args[]) throws Exception{
		System.out.println(encodePassword("AAAA","1111"));
		
		System.out.println(encodePassword("BBBB","1"));
		
		System.out.println(sha1("1111"));
		
		
	}
	
}



